package com.small.mybatis.session;

import com.small.mybatis.binding.MapperRegistry;
import com.small.mybatis.mapping.MappedStatement;
import com.small.mybatis.session.defaults.DefaultSqlSession;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author zhoujin
 * @Date 2022/4/21 14:18
 */
public class Configuration {

    private MapperRegistry mapperRegistry = new MapperRegistry(this);

    /**
     * 映射的语句，存在Map里
     */
    protected final Map<String, MappedStatement> mappedStatements = new HashMap<>();


    public <T>void addMapper(Class<T> type){
        mapperRegistry.addMappers(type);
    }

    public void addMappedStatement(MappedStatement ms) {
        mappedStatements.put(ms.getId(), ms);
    }

    public MappedStatement getMappedStatement(String id) {
        return mappedStatements.get(id);
    }

    public <T> T getMapper(Class<T> type, DefaultSqlSession defaultSqlSession) {
        return mapperRegistry.getMapper(type,defaultSqlSession);
    }
}
